home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 032a / acctxt2.zip / DDEWOR.TXT < prev    next >
Text File  |  1993-02-14  |  5KB  |  175 lines

  1. .TITLE: INF: Merging Records To Word For Windows Via DDE
  2. .VERSION(S): 1.00
  3. .OPERATING SYSTEM(S): WINDOWS
  4.  
  5. -----------------------------------------------------------
  6. The information in this article applies to:
  7.  
  8.  - Microsoft Access version 1.0
  9. -----------------------------------------------------------
  10.  
  11. Summary:
  12.  
  13. This article describes the steps for creating a form which 
  14. allows the user to press a button to send the current record 
  15. to Microsoft Word for Windows. The data sent is merged into 
  16. a pre-written letter and printed.
  17.  
  18. The article assumes that you understand Dynamic Data 
  19. Exchange, setting bookmarks in Word for Windows, and 
  20. creating modules in Microsoft Access. 
  21.  
  22. More Information:
  23.  
  24. Step One: Create the Winword Document
  25. -------------------------------------
  26. 1) Start Winword and open a new document.
  27.  
  28. 2) Type in the following:
  29.  
  30.  CompanyName
  31.  Address
  32.  City, Region, PostalCode
  33.  Country
  34.  
  35.  Dear ContactName,
  36.  
  37.  NorthWind Traders would like to thank you for 
  38.  your business during the past year.  Enclosed 
  39.  you will find several samples of new products 
  40.  that we are excited to announce.  
  41.  
  42.  Sincerely,
  43.  NorthWind Traders.
  44.  
  45. 3) Save this document as DDEMERGE.DOC.
  46.  
  47. 4) To create the bookmarks, highlight CompanyName and
  48.    choose Bookmark from the Insert menu.  Name the 
  49.    Bookmark "CompanyName", without quotes.
  50.  
  51. 5) Repeats these steps, creating bookmarks for the 
  52.    fields: Address, City, Region, PostalCode, Country,
  53.    and ContactName.
  54.  
  55.  
  56. Step Two: Create The Access Basic Modules
  57. =========================================
  58.  
  59. 1) Open the example database NWIND.MDB. (One of 
  60.    the following modules uses the function STARTAPP()
  61.    which is located in the module Introduction to 
  62.    Programming.
  63.  
  64. 2) Create a new module called Print Merge.
  65.  
  66. 3) Place the following statement in the (declarations) 
  67.    section:
  68.   Dim Mergechan As Integer  
  69.  
  70. 4) Create a new function called Initiate_Word () 
  71.  
  72.    Function Initiate_Word ()
  73.       Chan = StartApp("Winword", "System")
  74.  
  75.       On Error GoTo AlertUser:
  76.       WordTopics = DDERequest(Chan, "Topics")
  77.  
  78.       If InStr(1, WordTopics, "DDEMERGE.DOC") = 0 Then
  79.         DDEExecute Chan, "[FILEOPEN(""DDEMERGE.DOC"")]"
  80.       End If
  81.  
  82.       DDETerminate Chan
  83.       Mergechan = DDEInitiate("Winword", "DDEMERGE.DOC")
  84.  
  85.    Exit Function
  86.  
  87.    AlertUser:
  88.       MsgBox "Access is unable to initiate a DDE 
  89.    channel with the document DDETEST.DOC"
  90.       Resume Next 
  91.    End Function    
  92.  
  93. 5) Create a new function called Send_Record()
  94.  
  95.    Function Send_Record ()
  96.  
  97.      Dim Chan
  98.      Dim ControlName As Control
  99.      Dim BookMarks As String
  100.   
  101.      On Error GoTo CatchBlanks:
  102.  
  103.      DDEPoke Mergechan, "CompanyName", 
  104.    Forms![Customers DDE]![Company Name]
  105.      DDEPoke Mergechan, "ContactName", 
  106.    Forms![Customers DDE]![Contact Name]
  107.      DDEPoke Mergechan, "Address", 
  108.    Forms![Customers DDE]![Address]
  109.      DDEPoke Mergechan, "City", 
  110.    Forms![Customers DDE]![City]
  111.      DDEPoke Mergechan, "Region", 
  112.    Forms![Customers DDE]![Region]
  113.      DDEPoke Mergechan, "PostalCode", 
  114.    Forms![Customers DDE]![Postal Code]
  115.    
  116.      DDEExecute Mergechan, "[FilePrint]"
  117.     
  118.      Exit Function
  119.  
  120.    CatchBlanks:
  121.       If MsgBox("One of these fields is blank. Would
  122.     you like to continue?", 52) = 6 Then
  123.         Resume Next
  124.       Else
  125.         Exit Function
  126.       End If
  127.    End Function
  128.  
  129. Note: Each of the DDEPoke statements should be on one
  130.       line in your function.  They are split in this
  131.       article for readability.
  132.  
  133. 6) Create a function called Terminate_MergeChan():
  134.  
  135.    Function Terminate_MergeChan ()
  136.  
  137.     DDETerminate MergeChan
  138.  
  139.    End Function
  140.  
  141.  
  142. 7) Choose Compile All from the Run menu and then
  143.    close and save the module.
  144.  
  145.  
  146. Step Three: Create the Form
  147. =========================================
  148. 1) Open the form [Customers] in design mode.
  149.  
  150. 2) Set the OnOpen property of the form to:
  151.  =Initiate_Word()
  152.  
  153. 3) Set the OnClose property of the form to:
  154.  =Terminate_MergeChan()
  155.  
  156. 4) Add a new button to the Customers form.
  157.  
  158. 5) Set the Caption property of the button to:
  159.  Print Letter.
  160.  
  161. 6) Set the OnPush property of the button to:
  162.  =Send_Record()
  163.  
  164. 7) Save the form and switch to browse mode. Click on the
  165.    Print Letter button. The current record will be sent
  166.    to Word for Windows, merged into the document 
  167. DDEMERGE.DOC
  168.    and then printed.
  169.  
  170.  
  171. Reference(s):
  172. Introduction to Programming, Chapter 9 Dynamic Data 
  173. Exchange.
  174. Word for Windows Technical Reference pp. 20-25
  175.